//
//  StageScene.m
//  FrameWork
//
//  Created by waver on 10-8-5.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "StageScene.h"

@implementation StageLayer

static StageLayer* layer = nil;
static CCScene * scene = nil;
+(id)scene
{

	// 'scene' is an autorelease object.
	if(scene == nil)
		scene = [CCScene node];
	
	if(layer != nil)
		return scene;
	
	// 'layer' is an autorelease object.
 	layer = [StageLayer node];
	
	CLoadingW * pLoad = [CLoadingW ShareLoading];
	
	// add layer as a child to scene
	[scene addChild: layer z:2];
	
	[scene addChild:pLoad z:5];

	[layer init];
	return scene;
}

-(id) init
{
	// always call "super" init
	// Apple recommends to re-assign "self" with the "super" return value
	if( (self=[super init] ))
	{
		loadImageNum = 0;
		self.isTouchEnabled = YES;
		[self schedule:@selector(LoadImage) interval:1.0f];
	}
	loadImageNum = 0;
	selectStage = 0;
	selectMode = 0;
	return self;
}

-(void)SpriteInit
{

}

-(void)StageSelcetChange:(int)NewSelect
{
	if(selectMode == 1)//战役
	{
		Parameter * pPar = [Parameter sharedParameter];
		if(![pPar IsStageOpen:(NewSelect+1)])
			return;
	}
	[__stageFourSpr[selectStage] setTextureRect:CGRectMake(0,28, 158,28)];
	[__stageFourSpr[NewSelect] setTextureRect:CGRectMake(0, 56, 158, 28)];
	selectStage = NewSelect;
	[self DisplayInfo];
}

//选择虎牢关
-(void)SelectHuLao
{
	[self StageSelcetChange:0];
}
//选择长板坡
-(void)SelectChangBanPo
{
	[self StageSelcetChange:1];
}
//选择定君山
-(void)SelectDingJunShan
{
	[self StageSelcetChange:2];
}
//选择南中
-(void)SelectNanZhong
{
	[self StageSelcetChange:3];
}

//选择战役
-(void)SelectCampaignMode
{
	if(selectMode == 0)
		return;
	[self StageModeChange:0];
}
//选择自由
-(void)SelectFreeMode
{
	if(selectMode ==1)
		return;
	[self StageModeChange:1];
}


-(void)StageModeChange:(int)newMode
{
	Parameter * pPar = [Parameter sharedParameter];
	
	selectStage = 0;
	[self DisplayInfo];
	
	[__stageFourSpr[0] setTextureRect:CGRectMake(0,56, 158,28)];
	
	if(newMode == 0)
	{
		[__modeSelSpr[0] setTextureRect:CGRectMake(0,52, 78,26)];
		[__modeSelSpr[1] setTextureRect:CGRectMake(0,26, 78,26)];
	}
	else
	{
		[__modeSelSpr[1] setTextureRect:CGRectMake(0,52, 78,26)];
		[__modeSelSpr[0] setTextureRect:CGRectMake(0,26, 78,26)];
	}
	
	selectMode = newMode;
	
	if([pPar IsStageOpen:1])
	{
		if(newMode == 0)
		{
			[__stageNameSpr[1] setTextureRect:CGRectMake(0, 14, width, 14)];
		
			[__stageFourSpr[1] setTextureRect:CGRectMake(0,28, 158,28)];
		}
		else
		{
			[__stageNameSpr[1]  setTextureRect:CGRectMake(0, 56, width, 14)];
			[__stageFourSpr[1]  setTextureRect:CGRectMake(0,0, 158,28)];
		}


		if([pPar IsStageOpen:2])
		{
			if(newMode == 0)
			{
				[__stageNameSpr[2] setTextureRect:CGRectMake(0, 28, width, 14)];
				[__stageFourSpr[2]  setTextureRect:CGRectMake(0,28, 158,28)];
			}
			else
			{
				[__stageNameSpr[1] setTextureRect:CGRectMake(0, 14, width, 14)];
				[__stageFourSpr[1] setTextureRect:CGRectMake(0,28, 158,28)];
				[__stageNameSpr[2]  setTextureRect:CGRectMake(0, 70, width, 14)];
				[__stageFourSpr[2]  setTextureRect:CGRectMake(0,0, 158,28)];
			}

			
			if([pPar IsStageOpen:3])
			{
				if(newMode == 0)
				{
					[__stageNameSpr[3] setTextureRect:CGRectMake(0, 42, width, 14)];
					[__stageFourSpr[3]  setTextureRect:CGRectMake(0,28, 158,28)];
				}
				else
				{
					[__stageNameSpr[2] setTextureRect:CGRectMake(0, 28, width, 14)];
					[__stageFourSpr[2]  setTextureRect:CGRectMake(0,28, 158,28)];
					[__stageNameSpr[3]  setTextureRect:CGRectMake(0, 84, width, 14)];
					[__stageFourSpr[3]  setTextureRect:CGRectMake(0,0, 158,28)];
				}

			}
			else
			{
				[__stageNameSpr[3]  setTextureRect:CGRectMake(0, 84, width, 14)];
				[__stageFourSpr[3] setTextureRect:CGRectMake(0,0, 158,28)];
			}
			
		}
		else
		{
			[__stageNameSpr[2]  setTextureRect:CGRectMake(0, 70, width, 14)];
			[__stageNameSpr[3]  setTextureRect:CGRectMake(0, 84, width, 14)];
			[__stageFourSpr[2]  setTextureRect:CGRectMake(0,0, 158,28)];
			[__stageFourSpr[3]  setTextureRect:CGRectMake(0,0, 158,28)];
		}
	}
	else
	{
		[__stageNameSpr[1]  setTextureRect:CGRectMake(0, 56, width, 14)];
		[__stageNameSpr[2]  setTextureRect:CGRectMake(0, 70, width, 14)];
		[__stageNameSpr[3]  setTextureRect:CGRectMake(0, 84, width, 14)];
		[__stageFourSpr[1]  setTextureRect:CGRectMake(0,0, 158,28)];
		[__stageFourSpr[2]  setTextureRect:CGRectMake(0,0, 158,28)];
		[__stageFourSpr[3]  setTextureRect:CGRectMake(0,0, 158,28)];
	}

}

//选择开始游戏
-(void)BeginGame
{
	emitter = [CCParticleFlower node];
	emitter.texture = [[CCTextureCache sharedTextureCache] addImage: @"stars.png"];
	[__startSpr addChild:emitter z:10 tag:1];
	emitter.position = CGPointMake(30,0);
	id move = [CCMoveBy actionWithDuration:1 position:ccp(-400,300)];
	id move_back = [move reverse];
	id seq = [CCSequence actions: 
			  move,
			  move_back,
			  [CCCallFunc actionWithTarget:self selector:@selector(GotoGameNow)],
			  nil];
	[emitter runAction:[CCRepeatForever actionWithAction:seq]];

}

-(void)GotoGameNow
{
	[[Parameter sharedParameter] setStage:(selectStage+1)];
	[[Parameter sharedParameter] LoadFile];
	//[[CCDirector sharedDirector] replaceScene:[Game scene]];
	[[CCDirector sharedDirector] replaceScene:[Game scene]];
}

-(void)LoadImage
{
	
	[[CCTextureCache sharedTextureCache] addImageAsync:@"Select-campaign_back.png" target:self selector:@selector(LoadPictureOver)];
	[[CCTextureCache sharedTextureCache] addImageAsync:@"Select-campaign_Bbox.png" target:self selector:@selector(LoadPictureOver)];
	[[CCTextureCache sharedTextureCache] addImageAsync:@"Select-campaign_Mbox.png" target:self selector:@selector(LoadPictureOver)];
	[[CCTextureCache sharedTextureCache] addImageAsync:@"Select-campaign_num.png" target:self selector:@selector(LoadPictureOver)];
	[[CCTextureCache sharedTextureCache] addImageAsync:@"Select-campaign_Sbox.png" target:self selector:@selector(LoadPictureOver)];
	
	[[CCTextureCache sharedTextureCache] addImageAsync:@"Select-campaign_Word_back.png" target:self selector:@selector(LoadPictureOver)];
	[[CCTextureCache sharedTextureCache] addImageAsync:@"Select-campaign_Word_Mode.png" target:self selector:@selector(LoadPictureOver)];
	[[CCTextureCache sharedTextureCache] addImageAsync:@"Select-campaign_Word_Points.png" target:self selector:@selector(LoadPictureOver)];
	[[CCTextureCache sharedTextureCache] addImageAsync:@"Select-campaign_Word_Select.png" target:self selector:@selector(LoadPictureOver)];
	[[CCTextureCache sharedTextureCache] addImageAsync:@"Select-campaign_Word_Start.png" target:self selector:@selector(LoadPictureOver)];
	
	
	[[CCTextureCache sharedTextureCache] addImageAsync:@"changbanpo.png" target:self selector:@selector(LoadPictureOver)];
	[[CCTextureCache sharedTextureCache] addImageAsync:@"dingjun.png" target:self selector:@selector(LoadPictureOver)];
	[[CCTextureCache sharedTextureCache] addImageAsync:@"hulao.png" target:self selector:@selector(LoadPictureOver)];
	[[CCTextureCache sharedTextureCache] addImageAsync:@"nanzhong.png" target:self selector:@selector(LoadPictureOver)];
	
	
	
	int lan =[[GameSet GameSetShare] lanuage];
	if(lan == En)
	{
		[[CCTextureCache sharedTextureCache] addImageAsync:@"Select-campaign_Word_camEn.png" target:self selector:@selector(LoadPictureOver)];
	}
	else if(lan == ch_zh)
	{
		[[CCTextureCache sharedTextureCache] addImageAsync:@"Select-campaign_Word_camCn2.png" target:self selector:@selector(LoadPictureOver)];
	}
	else if(lan == ch_tw)
	{
		[[CCTextureCache sharedTextureCache] addImageAsync:@"Select-campaign_Word_camCn1.png" target:self selector:@selector(LoadPictureOver)];
	}
	[self unschedule:@selector(LoadImage)];
}

-(void)LoadPictureOver
{
	
	loadImageNum++;
	
	if(loadImageNum == 15)//图片加载完
	{
		[self unschedule:@selector(LoadImage)];//关闭图片加载
		Parameter * pPar = [Parameter sharedParameter];
		__groundSpr = [CCSprite spriteWithFile:@"Select-campaign_back.png"];
		
		__titleSprite = [CCSprite spriteWithFile:@"Select-campaign_back.png"];
		
		__mapSprite = [CCSprite spriteWithFile:@"HuLao.png"];
		
		__startSelSpr = [CCSprite spriteWithFile:@"Select-campaign_Bbox.png" rect:CGRectMake(0, 32, 262, 32)];
		
		int lan =[[GameSet GameSetShare] lanuage];
		NSString * strStage;
		
		if(lan == En)
		{
			__titleSprite = [CCSprite spriteWithFile:@"Select-campaign_Word_Select.png" rect:CGRectMake(0, 0, 98, 14)];
			__startWord = [CCSprite spriteWithFile:@"Select-campaign_Word_Start.png" rect:CGRectMake(0, 0, 82, 16)];
			__exploitSpr = [CCSprite spriteWithFile:@"Select-campaign_Word_Points.png" rect:CGRectMake(0, 0, 130, 14)];
			__modeNameSpr[0] = [CCSprite spriteWithFile:@"Select-campaign_Word_Mode.png" rect:CGRectMake(0, 0, 54, 14)];
			if([pPar IsStageOpen:1])
			{
				__modeNameSpr[1] = [CCSprite spriteWithFile:@"Select-campaign_Word_Mode.png" rect:CGRectMake(0, 14, 54, 14)];
			}
			else
			{
				__modeNameSpr[1] = [CCSprite spriteWithFile:@"Select-campaign_Word_Mode.png" rect:CGRectMake(54, 14, 54, 14)];
			}
			__backSpr = [CCSprite spriteWithFile:@"Select-campaign_Word_back.png" rect:CGRectMake(0, 0, 34, 16)];
			strStage = [NSString stringWithString:@"Select-campaign_Word_camEn.png"];
			width = 148;
		}
		else if(lan == ch_zh)
		{
			__titleSprite = [CCSprite spriteWithFile:@"Select-campaign_Word_Select.png" rect:CGRectMake(0, 28, 98, 14)];
			__startWord = [CCSprite spriteWithFile:@"Select-campaign_Word_Start.png" rect:CGRectMake(0, 32, 82, 16)];
			__exploitSpr = [CCSprite spriteWithFile:@"Select-campaign_Word_Points.png" rect:CGRectMake(0, 28, 130, 14)];
			__modeNameSpr[0] = [CCSprite spriteWithFile:@"Select-campaign_Word_Mode.png" rect:CGRectMake(0, 56, 54, 14)];
			
			if([pPar IsStageOpen:1])
			{
				__modeNameSpr[1] = [CCSprite spriteWithFile:@"Select-campaign_Word_Mode.png" rect:CGRectMake(0, 70, 54, 14)];
			}
			else
			{
				__modeNameSpr[1] = [CCSprite spriteWithFile:@"Select-campaign_Word_Mode.png" rect:CGRectMake(54, 70, 54, 14)];
			}
			__backSpr = [CCSprite spriteWithFile:@"Select-campaign_Word_back.png" rect:CGRectMake(0, 32, 34, 16)];
			width = 66;
			strStage = [NSString stringWithString:@"Select-campaign_Word_camCn2.png"];
		}
		else if(lan == ch_tw)
		{
			__titleSprite = [CCSprite spriteWithFile:@"Select-campaign_Word_Select.png" rect:CGRectMake(0,14, 98, 14)];
			__startWord = [CCSprite spriteWithFile:@"Select-campaign_Word_Start.png" rect:CGRectMake(0, 16, 82, 16)];
			__exploitSpr = [CCSprite spriteWithFile:@"Select-campaign_Word_Points.png" rect:CGRectMake(0, 14, 130, 14)];
			__modeNameSpr[0] = [CCSprite spriteWithFile:@"Select-campaign_Word_Mode.png" rect:CGRectMake(0, 28, 54, 14)];
			
			if([pPar IsStageOpen:1])
			{
				__modeNameSpr[1] = [CCSprite spriteWithFile:@"Select-campaign_Word_Mode.png" rect:CGRectMake(0, 42, 54, 14)];
			}
			else
			{
				__modeNameSpr[1] = [CCSprite spriteWithFile:@"Select-campaign_Word_Mode.png" rect:CGRectMake(54, 42, 54, 14)];
			}
			
			__backSpr = [CCSprite spriteWithFile:@"Select-campaign_Word_back.png" rect:CGRectMake(0, 16, 34, 16)];
			width = 66;
			strStage = [NSString stringWithString:@"Select-campaign_Word_camCn1.png"];
		}
		__stageNameSpr[0] = [CCSprite spriteWithFile:strStage rect:CGRectMake(0, 0, width, 14)];
		__stageFourSpr[0] = [CCSprite spriteWithFile:@"Select-campaign_Mbox.png" rect:CGRectMake(0,56, 158,28)];
		__modeSelSpr[0] = [CCSprite spriteWithFile:@"Select-campaign_Sbox.png" rect:CGRectMake(0,52, 78,26)];
	
		if([pPar IsStageOpen:1])
		{
			__stageNameSpr[1] = [CCSprite spriteWithFile:strStage rect:CGRectMake(0, 14, width, 14)];
			
			__stageFourSpr[1] = [CCSprite spriteWithFile:@"Select-campaign_Mbox.png" rect:CGRectMake(0,28, 158,28)];
			
			__modeSelSpr[1] = [CCSprite spriteWithFile:@"Select-campaign_Sbox.png" rect:CGRectMake(0,26, 78,26)];
			
			
			if([pPar IsStageOpen:2])
			{
				__stageNameSpr[2] = [CCSprite spriteWithFile:strStage rect:CGRectMake(0, 28, width, 14)];
				__stageFourSpr[2] = [CCSprite spriteWithFile:@"Select-campaign_Mbox.png" rect:CGRectMake(0,28, 158,28)];
				
				if([pPar IsStageOpen:3])
				{
					__stageNameSpr[3] = [CCSprite spriteWithFile:strStage rect:CGRectMake(0, 42, width, 14)];
					__stageFourSpr[3] = [CCSprite spriteWithFile:@"Select-campaign_Mbox.png" rect:CGRectMake(0,28, 158,28)];
				}
				else
				{
					__stageNameSpr[3] = [CCSprite spriteWithFile:strStage rect:CGRectMake(0, 84, width, 14)];
					__stageFourSpr[3] = [CCSprite spriteWithFile:@"Select-campaign_Mbox.png" rect:CGRectMake(0,0, 158,28)];
				}
				
			}
			else
			{
				__stageNameSpr[2] = [CCSprite spriteWithFile:strStage rect:CGRectMake(0, 70, width, 14)];
				__stageNameSpr[3] = [CCSprite spriteWithFile:strStage rect:CGRectMake(0, 84, width, 14)];
				__stageFourSpr[2] = [CCSprite spriteWithFile:@"Select-campaign_Mbox.png" rect:CGRectMake(0,0, 158,28)];
				__stageFourSpr[3] = [CCSprite spriteWithFile:@"Select-campaign_Mbox.png" rect:CGRectMake(0,0, 158,28)];
			}
		}
		else
		{
			__stageNameSpr[1] = [CCSprite spriteWithFile:strStage rect:CGRectMake(0, 56, width, 14)];
			__stageNameSpr[2] = [CCSprite spriteWithFile:strStage rect:CGRectMake(0, 70, width, 14)];
			__stageNameSpr[3] = [CCSprite spriteWithFile:strStage rect:CGRectMake(0, 84, width, 14)];
			__stageFourSpr[1] = [CCSprite spriteWithFile:@"Select-campaign_Mbox.png" rect:CGRectMake(0,0, 158,28)];
			__stageFourSpr[2] = [CCSprite spriteWithFile:@"Select-campaign_Mbox.png" rect:CGRectMake(0,0, 158,28)];
			__stageFourSpr[3] = [CCSprite spriteWithFile:@"Select-campaign_Mbox.png" rect:CGRectMake(0,0, 158,28)];
			__modeSelSpr[1] = [CCSprite spriteWithFile:@"Select-campaign_Sbox.png" rect:CGRectMake(0,0, 78,26)];
		}
		__startSpr = [CCSprite node];
		CGSize startSize;
		startSize.width = 262;
		startSize.height = 32;
		__startSpr.contentSize = startSize;
		[self addChild:__backSpr z:3];
		[self addChild:__titleSprite z:3];
		[self addChild:__mapSprite z:1];
		[self addChild:__groundSpr z:2];
		__groundSpr.position = CGPointMake(240, 160);
		[self addChild:__startSpr z:10];
		[self addChild:__exploitSpr z:3];
		[self addChild:__stageFourSpr[0] z:4];
		[self addChild:__stageFourSpr[1] z:5];
		[self addChild:__stageFourSpr[2] z:6];
		[self addChild:__stageFourSpr[3] z:7];
		
		[self addChild:__modeSelSpr[0] z:3];
		[self addChild:__modeSelSpr[1] z:3];
		
		__backSpr.position = CGPointMake(17, 320-8);
		__titleSprite.position = CGPointMake(244, 320-56);
		__stageFourSpr[0].position = CGPointMake(20+79, 320-94-14);
		__stageFourSpr[1].position = CGPointMake(99, 320-136-14);
		__stageFourSpr[2].position = CGPointMake(99, 320-178-14);
		__stageFourSpr[3].position = CGPointMake(99, 320-220-14);
		__modeSelSpr[0].position = CGPointMake(248+39, 320-94-13);
		__modeSelSpr[1].position = CGPointMake(332+39, 320-94-13);
		__startSpr.position = CGPointMake(197+131, 320-273-16);
		if(lan == ch_tw ||lan == ch_zh)
			__exploitSpr.position = CGPointMake(33, 8);
		else
		{
			__exploitSpr.position = CGPointMake(115, 8);
		}

		
		__mapSprite.position = CGPointMake(195+130, 85+85);
		__mapSprite.scaleX = 260.0/720.0;
		__mapSprite.scaleY = 170.0/480.0;
		
		for(int i=0;i<4;i++)
		{
			[__stageFourSpr[i] addChild:__stageNameSpr[i] z:10];
			__stageNameSpr[i].position = CGPointMake(79,14);
		}
		
		[__startSpr addChild:__startSelSpr z:1];
		[__startSpr addChild:__startWord z:2];
		__startSelSpr.position = CGPointMake(131, 16);
		__startWord.position = CGPointMake(131, 16);
		
		[__modeSelSpr[0] addChild:__modeNameSpr[0] z:2];
		[__modeSelSpr[1] addChild:__modeNameSpr[1] z:2];
		__modeNameSpr[0].position = CGPointMake(39, 13);
		__modeNameSpr[1].position = CGPointMake(39, 13);
		
		//loading动画结束
		CLoadingW * pLoad = [CLoadingW ShareLoading];
		[scene removeChild:pLoad cleanup:NO];
/*		if(pLoad.loadingOver)
		{
			[scene removeChild:pLoad cleanup:YES];
		}
		else
		{
			[self schedule:@selector(CheckLoadOver) interval:1.0f];
		}*/
		
		__moneyB = [CDrawNumberW alloc];
		[__moneyB initWithFile:@"stars.png" rect:CGRectMake(0, 0, 1, 1)];
		__waveB = [CDrawNumberW alloc];
		[__waveB initWithFile:@"stars.png" rect:CGRectMake(0, 0, 1, 1)];
		__cityHpB = [CDrawNumberW alloc];
		[__cityHpB initWithFile:@"stars.png" rect:CGRectMake(0, 0, 1, 1)];
		[self addChild:__moneyB z:8 ];
		[self addChild:__waveB z:8 ];
		[self addChild:__cityHpB z:8 ];
		[self DisplayInfo];
		

	}
}

-(void)CheckLoadOver
{
	CLoadingW * pLoad = [CLoadingW ShareLoading];
	if(pLoad.loadingOver)
	{
		[scene removeChild:pLoad cleanup:NO];
		[self unschedule:@selector(CheckLoadOver)];
	}
	else
	{
		[self schedule:@selector(CheckLoadOver) interval:1.0f];
	}
}

-(CGRect)RectFromSprite:(CCSprite *) pSprite
{
	int x = pSprite.position.x -pSprite.contentSize.width/2.0;
	int y = pSprite.position.y - pSprite.contentSize.height/2.0;
	return CGRectMake(x, y, pSprite.contentSize.width, pSprite.contentSize.height);
}

-(void) registerWithTouchDispatcher
{
	[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:NO];
}

-(BOOL) ccTouchBegan:(UITouch*)touch withEvent:(UIEvent*)event
{
	Parameter * pPar = [Parameter sharedParameter];
	
	CGPoint location = [touch locationInView: [touch view]];
	CGPoint convertedLocation = [[CCDirector sharedDirector] convertToGL:location];
	
	//返回主菜单
	CGRect backRect = CGRectMake(__backSpr.position.x, __backSpr.position.y, __backSpr.contentSize.width, __backSpr.contentSize.height);
	
	if(CGRectContainsPoint(backRect,convertedLocation))
	{
		[self BackMainScene];
		return YES;
	}
	
	
	
	//开始游戏
	CGRect startRect = [self RectFromSprite:__startSpr];
	if(CGRectContainsPoint(startRect,convertedLocation))
	{
		[self BeginGame];
		return YES;
	}
	
	
	
	
	//关卡1选择
	CGRect StageOneRect = [self RectFromSprite:__stageFourSpr[0]];
	if(CGRectContainsPoint(StageOneRect,convertedLocation))//关卡1
	{
		[self SelectHuLao];
	}
	
	if([pPar IsStageOpen:1])//关卡一解开
	{
		//模式选择
		CGRect ModeOneRect = [self RectFromSprite:__modeSelSpr[0]];
		CGRect ModeTwoRect = [self RectFromSprite:__modeSelSpr[1]];
		if(CGRectContainsPoint(ModeOneRect,convertedLocation))//战役
		{
			[self SelectCampaignMode];
		}
		
		if(CGRectContainsPoint(ModeTwoRect,convertedLocation))//自由模式
		{
			[self SelectFreeMode];
		}
		
		//关卡2选择
		CGRect StageTwoRect = [self RectFromSprite:__stageFourSpr[1]];
		if(CGRectContainsPoint(StageTwoRect,convertedLocation))//关卡2
		{
			[self SelectChangBanPo];
		}
		
		if([pPar IsStageOpen:2])//关卡2解开
		{
			CGRect StageThreeRect = [self RectFromSprite:__stageFourSpr[2]];
			if(CGRectContainsPoint(StageThreeRect,convertedLocation))//关卡3
			{
				[self SelectDingJunShan];
			}
			
			if([pPar IsStageOpen:3])//关卡3解开
			{
				CGRect StageFourRect = [self RectFromSprite:__stageFourSpr[3]];
				if(CGRectContainsPoint(StageFourRect,convertedLocation))//关卡4
				{
					[self SelectNanZhong];
				}
			}
		}
		
	}
	return YES;
}
- (void)ccTouchMoved:(UITouch*)touch withEvent:(UIEvent *)event
{
	//CGPoint location = [touch locationInView: [touch view]];
	//CGPoint convertedLocation = [[CCDirector sharedDirector] convertToGL:location];
	
}

- (void)ccTouchEnded:(UITouch*)touch withEvent:(UIEvent *)event
{
	//CGPoint location = [touch locationInView: [touch view]];
	//CGPoint convertedLocation = [[CCDirector sharedDirector] convertToGL:location];
		
}

-(void)BackMainScene
{
	
}

-(void)DisplayInfo
{

	
	[__moneyB removeAllChildrenWithCleanup:YES];
	[__waveB removeAllChildrenWithCleanup:YES];
	[__cityHpB removeAllChildrenWithCleanup:YES];
	
	Parameter * pPar = [Parameter sharedParameter];
	int money = [pPar beginMoney:selectStage];
	int wave  = [pPar waveNumber:selectStage];
	int cityHp = [pPar cityHp:selectStage];
	
	[__moneyB NumberImage:@"Select-campaign_num.png"];
	[__waveB NumberImage:@"Select-campaign_num.png"];
	[__cityHpB NumberImage:@"Select-campaign_num.png"];
	

	[__moneyB DrawNumber:money FirstPoint:CGPointMake(260, 320-240) xOff:-4];
	[__waveB DrawNumber:wave FirstPoint:CGPointMake(328, 320-240) xOff:-4];
	[__cityHpB DrawNumber:cityHp FirstPoint:CGPointMake(390, 320-240) xOff:-4];
	
	
}




@end